package cn.tedu.start.controller.petcontroller;

import cn.tedu.commons.response.JsonResult;
import cn.tedu.pojo.pet.dto.PetCommodityDTO;
import cn.tedu.pojo.pet.vo.PetCommodityVO;
import cn.tedu.pojo.pet.vo.PetDetailsVO;
import cn.tedu.service.petcommodity.IPetCommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@Api(tags = "3，宠物商品模块")
@RestController
@RequestMapping("/petcommodity")
public class PetCommodityController {
    @Autowired(required = false)
    private IPetCommodityService petCommodityService;

    @ApiOperation("管理员添加商品")
    @PostMapping("/add")
    public JsonResult addCommodity( PetCommodityDTO petCommodityDTO){
        petCommodityService.addCommodity(petCommodityDTO);
        return JsonResult.ok("添加商品成功");
    }

    @ApiOperation("管理员修改宠物商品")
    @GetMapping("/update")
    public JsonResult updateCommodity(String oldName,String newName){
        System.out.println(oldName+"------"+newName);
        petCommodityService.updatePetCommodity(oldName,newName);
        return JsonResult.ok("修改宠物商品成功");
    }

    @ApiOperation("管理员修改宠物是否启用")
    @GetMapping("/update/delete")
    public JsonResult updateIsDelete(String commodityName,Integer isDelete){
        petCommodityService.updateIsDelete(commodityName,isDelete);
        return JsonResult.ok("修改宠物启用状态成功");
    }

    @ApiOperation("根据品种类型展示商品列表")
    @GetMapping("/listname")
    public JsonResult<List<PetCommodityVO>> listByCategoryName(String categoryName){
        System.out.println("获取的名字为："+categoryName);
        return JsonResult.ok(petCommodityService.listByCategoryName(categoryName));
    }

    @ApiOperation("根据指定商品名字获取相应详情信息")
    @GetMapping("/listname/details")
    public JsonResult<PetDetailsVO> listDetailsByCommodityName(String  commodityName){
        System.out.println("获取的信息为："+commodityName);
        return JsonResult.ok(petCommodityService.listDetailsByCommodityName(commodityName));
    }

}
